package com.xyhy.starter.web.hutool;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Objects;

import com.xyhy.core.utils.time.LocalDateUtil;

import cn.hutool.core.convert.AbstractConverter;
import cn.hutool.core.util.NumberUtil;

public class LocalDateTimeConverter extends AbstractConverter<LocalDateTime> {
  private static final long serialVersionUID = 1L;

  @Override
  protected LocalDateTime convertInternal(Object value) {
    Long mills = null;
    if (value instanceof Calendar) {
      mills = ((Calendar) value).getTimeInMillis();
    } else if (value instanceof Long) {
      mills = (Long) value;
    } else if (value instanceof String && NumberUtil.isLong(value.toString())) {
      mills = Long.parseLong(value.toString());
    } else if (value instanceof LocalDateTime) {
      return (LocalDateTime) value;
    }

    if (Objects.nonNull(mills)) {
      return LocalDateUtil.parseLocalDateTime(mills);
    }

    try {
      return LocalDateUtil.parseLocalDateTime(convertToStr(value));
    } catch (Exception var6) {
      var6.printStackTrace();
    }
    return null;
  }

}
